//
//  JieXiaoSecTion1Cell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/18.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

enum JieXiaoType {
    case jjjiexiaoJoninType //即将揭晓参与
    case unJoinType//未参与揭晓
    case goingjieXiaoType//正在揭晓参与
    case zhongchouType//众筹中
}

class JieXiaoSecTion1Cell: UITableViewCell {
    
    var progressView:UIProgressView = UIProgressView.init(progressViewStyle: .default)
    
    var needLabel:UILabel = UILabel.init()
    
    var tagLabel:UILabel = UILabel.init()
    
    var djsBgView:UIView = UIView.init()
    
    var infoBgView:UIView = UIView.init()
    
    var tagJiexiaoLabel:UILabel = UILabel.init()
    
    var downTimeLabel:UILabel = UILabel.init()
    
    var refreshView:UIImageView = UIImageView.init()
    
    var djsLabel:UILabel = UILabel.init()
    
    var jxDjsLabel:UILabel = UILabel.init()
    
    var mineJoinLabel:UILabel = UILabel.init()
    
    var moreButton:UIButton = UIButton.init()
    
    var redLabel:UILabel = UILabel.init()
    
    var cellType:JieXiaoType?{
        didSet{
            switch cellType! {
            case .jjjiexiaoJoninType:
                //即将揭晓Type，正在揭晓
                break
            case .unJoinType:
                //未参与揭晓
                break
           case .goingjieXiaoType :
                //正在揭晓参与
                break
            default :
                //众筹中
                break
        }
    }
}
    var detailModel:ProductDetailModel?{
        didSet{
            //更新UI
            switch cellType! {
            case .jjjiexiaoJoninType:
                //即将揭晓Type，正在揭晓
                self.infoBgView.addSubview(self.moreButton)
                break
            case .unJoinType:
                //未参与揭晓
                self.mineJoinLabel.textColor = BaseFontColor
                self.mineJoinLabel.font = UIFont.systemFont(ofSize: 14)
                self.mineJoinLabel.textAlignment = .center
                self.mineJoinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.right.equalTo(0)
                    make.top.equalTo(13)
                    make.height.equalTo(14)
                })
                break
            case .goingjieXiaoType:
                //正在揭晓参与
                self.infoBgView.addSubview(self.moreButton)
                self.infoBgView.addSubview(self.redLabel)
                self.redLabel.font = UIFont.systemFont(ofSize: 12)
                self.redLabel.textColor = .red
                self.redLabel.textAlignment = .center
                self.mineJoinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(12)
                    make.top.equalTo(12)
                    make.height.equalTo(12)
                    make.right.equalTo(-60)
                })
                self.moreButton.snp.makeConstraints({ (make) in
                    make.left.equalTo(self.mineJoinLabel.snp.right).offset(0)
                    make.top.equalTo(5)
                    make.height.equalTo(15)
                    make.right.equalTo(-5)
                })
                self.redLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.right.equalTo(0)
                    make.height.equalTo(12)
                    make.top.equalTo(self.mineJoinLabel.snp.bottom).offset(6)
                })
                break
            default :
                //众筹中的商品
//                self.djsBgView.isHidden = true
                self.mineJoinLabel.textColor = BaseFontColor
                self.mineJoinLabel.font = UIFont.systemFont(ofSize: 14)
                self.mineJoinLabel.textAlignment = .center
                self.mineJoinLabel.snp.makeConstraints({ (make) in
                    make.left.equalTo(0)
                    make.right.equalTo(0)
                    make.top.equalTo(13)
                    make.height.equalTo(14)
                })
                break
            }
        }
    }
//    var dataDic:[String:String]?{
//        didSet{
//            //更新UI
//            switch cellType! {
//            case .jjjiexiaoJoninType:
//                //即将揭晓Type，正在揭晓
//                self.infoBgView.addSubview(self.moreButton)
//                break
//            case .unJoinType:
//                //未参与揭晓
//                self.mineJoinLabel.textColor = BaseFontColor
//                self.mineJoinLabel.font = UIFont.systemFont(ofSize: 14)
//                self.mineJoinLabel.textAlignment = .center
//                self.mineJoinLabel.snp.makeConstraints({ (make) in
//                    make.left.equalTo(0)
//                    make.right.equalTo(0)
//                    make.top.equalTo(13)
//                    make.height.equalTo(14)
//                })
//                break
//            case .goingjieXiaoType:
//                //正在揭晓参与
//                self.infoBgView.addSubview(self.moreButton)
//                self.infoBgView.addSubview(self.redLabel)
//                self.redLabel.font = UIFont.systemFont(ofSize: 12)
//                self.redLabel.textColor = .red
//                self.redLabel.textAlignment = .center
//                self.mineJoinLabel.snp.makeConstraints({ (make) in
//                    make.left.equalTo(12)
//                    make.top.equalTo(12)
//                    make.height.equalTo(12)
//                    make.right.equalTo(-60)
//                })
//                self.moreButton.snp.makeConstraints({ (make) in
//                    make.left.equalTo(self.mineJoinLabel.snp.right).offset(0)
//                    make.top.equalTo(5)
//                    make.height.equalTo(15)
//                    make.right.equalTo(-5)
//                })
//                self.redLabel.snp.makeConstraints({ (make) in
//                    make.left.equalTo(0)
//                    make.right.equalTo(0)
//                    make.height.equalTo(12)
//                    make.top.equalTo(self.mineJoinLabel.snp.bottom).offset(6)
//                })
//                break
//            default :
//                //众筹中的商品
//                self.djsBgView.isHidden = true
//                self.mineJoinLabel.textColor = BaseFontColor
//                self.mineJoinLabel.font = UIFont.systemFont(ofSize: 14)
//                self.mineJoinLabel.textAlignment = .center
//                self.mineJoinLabel.snp.makeConstraints({ (make) in
//                    make.left.equalTo(0)
//                    make.right.equalTo(0)
//                    make.top.equalTo(13)
//                    make.height.equalTo(14)
//                })
//                break
//            }
//        }
//    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
extension JieXiaoSecTion1Cell{
    func setUI(){
       self.contentView.addSubview(self.progressView)
        self.contentView.addSubview(self.needLabel)
        self.contentView.addSubview(self.tagLabel)
        self.contentView.addSubview(self.djsBgView)
        self.contentView.addSubview(self.infoBgView)
        self.progressView.progressTintColor = .orange
        self.progressView.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.top.equalTo(12)
            make.height.equalTo(10)
        }
        self.needLabel.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.width.equalTo((k_Wide-32)/2)
            make.top.equalTo(self.progressView.snp.bottom).offset(10)
            make.height.equalTo(12)
        }
        self.tagLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self.needLabel.snp.right).offset(0)
            make.right.equalTo(-16)
            make.top.equalTo(self.needLabel)
            make.height.equalTo(12)
        }
        self.djsBgView.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.top.equalTo(self.needLabel.snp.bottom).offset(12)
            make.height.equalTo(40)
            make.right.equalTo(-16)
        }
        self.infoBgView.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.right.equalTo(-16)
            make.height.equalTo(40)
            make.top.equalTo(self.djsBgView.snp.bottom).offset(4)
        }
        self.djsBgView.addSubview(self.djsLabel)
        self.djsBgView.addSubview(self.tagJiexiaoLabel)
        self.djsBgView.addSubview(self.refreshView)
        self.infoBgView.addSubview(self.mineJoinLabel)
        self.djsBgView.backgroundColor = .red
        self.infoBgView.backgroundColor = BackGroundColor
        self.tagJiexiaoLabel.textColor = .white
        self.djsLabel.textColor = .white
        self.djsLabel.textAlignment = .center
        self.tagLabel.textAlignment = .right
        self.tagJiexiaoLabel.font = UIFont.systemFont(ofSize: 14)
        self.djsLabel.font = UIFont.systemFont(ofSize: 24)
        self.tagJiexiaoLabel.textAlignment = .right
        self.tagJiexiaoLabel.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.width.equalTo(80)
            make.top.equalTo(13)
            make.height.equalTo(14)
        }
        self.refreshView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize.init(width: 16, height: 14))
            make.right.equalTo(-5)
            make.top.equalTo(13)
        }
        self.djsLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self.tagJiexiaoLabel.snp.right).offset(0)
            make.right.equalTo(self.refreshView.snp.left).offset(0)
            make.top.equalTo(8)
            make.height.equalTo(24)
        }
        self.refreshView.image = UIImage.init(named: "ic_shuaxin")
    }
}
